package game.monster
{
	import com.yzy.models.SetLibs;
	import com.yzy.motion.Auto;
	import com.yzy.motion.Vector2D;
	import com.yzy.tool.Utils;
	
	import flash.geom.Rectangle;
	
	import control.IRunCtrl;
	
	import starling.core.Starling;
	import starling.display.MovieClip;
	import starling.display.Sprite;
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;
	
	public class Monster extends Sprite implements IRunCtrl
	{
		private var mc:MovieClip;
		
		private var auto:Auto;
		
		public function Monster(name:String,rect:Rectangle,fps:int=12)
		{
			super();
			auto=new Auto();
			auto.rect=rect;
			initMc(name,fps);
		}
		private function initMc(name:String,fps:int):void{
			var monsterxml:XML=new XML(String(SetLibs.getLibsData(name)));
			var monsterTexture:Texture=Texture.fromBitmapData(SetLibs.getBitmapData(name));
			var stextureAtlas:TextureAtlas=new TextureAtlas(monsterTexture,monsterxml);
			var frames:Vector.<Texture>=stextureAtlas.getTextures(name);
			//
			mc=new MovieClip(frames,fps);
			mc.pivotX=mc.width>>1;
			mc.pivotY=mc.height>>1;
			//
//			this.x=200;
//			this.y=160;
			this.addChild(mc);
//			mc.x=-mc.width>>1;
//			mc.y=-mc.height>>1;
			mc.play();
			Starling.juggler.add(mc);
			//
			auto.position=new Vector2D(this.x,this.y);
			auto.velocity=new Vector2D();
			auto.velocity.length=1;
			auto.velocity.angle=Math.PI/4;
		
			mc.rotation=auto.velocity.angle;
		}
		public function Run(CurrNum:int):void
		{
//			auto.wander();
			auto.updata();
			this.x=auto.returnPoint.x;
			this.y=auto.returnPoint.y;
			mc.rotation=auto.returnRotation;
		}
	}
}